<template>
	<view class="container container329916">
		<view v-if="globalData.isshow" class="flex flex-wrap diygw-col-24 flex-direction-column">
			<view class="flex flex-wrap diygw-col-24 items-stretch flex7-clz">
				<view class="flex flex-wrap diygw-col-0 flex-direction-column justify-between items-center flex6-clz">
					<view class="flex flex-wrap diygw-col-24 items-center">
						<text class="diygw-col-0 text5-clz"> 收货人：{{ data.data.body.address.title }} </text>
						<text class="diygw-col-0 text6-clz">
							{{ data.data.body.address.phone }}
						</text>
					</view>
					<text class="diygw-text-line1 diygw-col-24 text30-clz"> {{ data.data.body.address.provinceLabel }}{{ data.data.body.address.address }} </text>
				</view>
			</view>
			<view v-for="(item, index) in data.data.body.carts" :key="index" class="flex flex-wrap diygw-col-24 items-center flex5-clz">
				<view class="flex flex-wrap diygw-col-0 items-stretch flex4-clz">
					<image :src="item.img" class="image-size diygw-image diygw-col-0 image-clz" mode="scaleToFill"></image>
					<view class="flex flex-wrap diygw-col-0 flex-direction-column justify-between flex2-clz">
						<text class="diygw-text-line2 diygw-col-24 text-clz">
							{{ item.title }}
						</text>
						<view class="flex flex-wrap diygw-col-24 justify-between items-center">
							<text class="diygw-text-line2 diygw-col-0 text2-clz"> {{ item.price }}*{{ item.number }}={{ item.total }} </text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="globalData.isshow" class="flex diygw-col-24 justify-between items-center diygw-bottom flex-nowrap flex-clz">
			<view class="flex flex-wrap diygw-col-0 items-center" @tap="navigateTo" data-type="selectAllFunction">
				<text class="diygw-col-0"> 合计： </text>
				<text class="diygw-col-0 text3-clz"> {{ data.data.total }}元 </text>
			</view>
			<text v-if="userInfo.token" @tap="navigateTo" data-type="payFunction" class="diygw-col-0 text4-clz"> 立即支付 </text>
			<text v-else @tap="navigateTo" data-type="page" data-url="/pages/login" class="diygw-col-0 text10-clz"> 还未登录，立即登录 </text>
		</view>
		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: { isshow: false, ispay: false },
				dataNum: 1,
				data: {
					code: 0,
					msg: '',
					data: {
						id: 0,
						title: '',
						total: '',
						body: '',
						status: 0,
						platform: '',
						openid: null,
						orderNo: '',
						payStatus: 0,
						transactionId: '',
						userId: 0,
						createTime: '',
						updateTime: '',
						deleteTime: null
					}
				}
			};
		},
		computed: {},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				await this.dataApi();
			},
			// 列表数据 API请求方法
			async dataApi(param) {
				let thiz = this;
				param = param || {};

				//如果请求要重置页面，请配置点击附加参数refresh=1  增加判断如输入框回调param不是对象
				if (param.refresh || typeof param != 'object') {
					this.dataNum = 1;
				}

				//请求地址及请求数据，可以在加载前执行上面增加自己的代码逻辑
				let http_url = '/shop/order/get';
				let http_data = {
					pageNum: this.dataNum,
					pageSize: 10,
					id: param.id || this.globalOption.id || '20'
				};
				let http_header = {};

				let data = await this.$http.post(http_url, http_data, http_header, 'json');

				if (!data.data) {
					this.showToast('订单不存在');
					uni.navigateBack();
					return;
				}
				data.data.body = JSON.parse(data.data.body);
				data.data.body.carts.forEach((item) => {
					item.total = item.price * item.number;
				});

				let datarows = data.rows;
				if (http_data.pageNum == 1) {
					this.data = data;
				} else if (datarows) {
					let rows = this.data.rows.concat(datarows);
					data.rows = rows;
					this.data = data;
				}
				if (datarows && datarows.length > 0) {
					this.dataNum = this.dataNum + 1;
				}
				this.globalData.isshow = true;
			},

			// UNIAPP微信支付调用 自定义方法
			async payFunction(param) {
				let thiz = this;
				//防止重复点击或点击过快
				if (this.globalData.ispay) {
					return;
				}
				thiz.globalData.ispay = true;
				this.navigateTo({
					type: 'pay',
					//下单地址返回微信支付相关参数
					url: '/shop/order/order',
					//微信支付
					paytype: 'weixin',
					//购买价格
					total: this.data.data.total,
					//购买商标描述
					body: this.data.data.title,
					//扩展参数
					param: {
						//比如订单号
						id: this.data.data.id
					},
					//支付成功回调，回调里的方法调用使用thiz.来调用，用this.会报错找不到相关方法
					success() {
						thiz.showToast('支付成功');
						thiz.gloablData.ispay = false;
					},
					//支付失败回调
					fail() {
						thiz.showToast('支付失败');
						thiz.gloablData.ispay = false;
					}
				});
			}
		},
		onPullDownRefresh() {
			// 列表数据 API请求方法
			this.dataNum = 1;
			this.dataApi();

			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			// 列表数据 API请求方法
			this.dataApi();
		}
	};
</script>

<style lang="scss" scoped>
	.flex7-clz {
		padding-top: 20rpx;
		border-bottom-left-radius: 24rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		border-top-right-radius: 24rpx;
		margin-right: 20rpx;
		background-color: #ffffff;
		margin-left: 20rpx;
		overflow: hidden;
		width: calc(100% - 20rpx - 20rpx) !important;
		border-top-left-radius: 24rpx;
		margin-top: 20rpx;
		border-bottom-right-radius: 24rpx;
		margin-bottom: 20rpx;
		padding-right: 20rpx;
	}
	.flex6-clz {
		flex: 1;
	}
	.text5-clz {
		flex: 1;
		font-size: 28rpx !important;
	}
	.text6-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}
	.text30-clz {
		margin-left: 0rpx;
		color: #989898;
		flex: 1;
		width: calc(100% - 0rpx - 0rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 0rpx;
		margin-right: 0rpx;
	}
	.flex5-clz {
		padding-top: 20rpx;
		border-bottom-left-radius: 24rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		border-top-right-radius: 24rpx;
		margin-right: 20rpx;
		background-color: #ffffff;
		margin-left: 20rpx;
		overflow: hidden;
		width: calc(100% - 20rpx - 20rpx) !important;
		border-top-left-radius: 24rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 24rpx;
		margin-bottom: 10rpx;
		padding-right: 20rpx;
	}
	.flex4-clz {
		flex: 1;
	}
	.image-clz {
		border: 2rpx solid #eee;
		border-bottom-left-radius: 12rpx;
		text-shadow: 1px 1px 2px #333;
		overflow: hidden;
		border-top-left-radius: 12rpx;
		border-top-right-radius: 12rpx;
		border-bottom-right-radius: 12rpx;
	}
	.image-size {
		height: 160rpx !important;
		width: 160rpx !important;
	}
	.flex2-clz {
		padding-top: 0rpx;
		flex: 1;
		padding-left: 10rpx;
		padding-bottom: 0rpx;
		padding-right: 0rpx;
	}
	.text-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}
	.text2-clz {
		padding-top: 6rpx;
		color: #ff2a2a;
		font-weight: bold;
		padding-left: 0rpx;
		font-size: 32rpx !important;
		padding-bottom: 6rpx;
		padding-right: 0rpx;
	}
	.flex-clz {
		background-color: #ffffff;
		padding-top: 20rpx;
		border-bottom-left-radius: 0rpx;
		overflow: hidden;
		left: 0rpx;
		bottom: 0rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		border-top-left-radius: 24rpx;
		border-top-right-radius: 24rpx;
		border-bottom-right-radius: 0rpx;
		padding-right: 20rpx;
	}
	.text3-clz {
		padding-top: 6rpx;
		color: #ff2a2a;
		font-weight: bold;
		padding-left: 0rpx;
		font-size: 32rpx !important;
		padding-bottom: 6rpx;
		padding-right: 0rpx;
	}
	.text4-clz {
		padding-top: 16rpx;
		border-bottom-left-radius: 200rpx;
		color: #ffffff;
		font-weight: bold;
		padding-left: 30rpx;
		font-size: 28rpx !important;
		padding-bottom: 16rpx;
		border-top-right-radius: 200rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		border-top-left-radius: 200rpx;
		margin-top: 0rpx;
		border-bottom-right-radius: 200rpx;
		background-image: linear-gradient(to right, #fa2209, #ff6335);
		margin-bottom: 0rpx;
		padding-right: 30rpx;
	}
	.text10-clz {
		padding-top: 16rpx;
		border-bottom-left-radius: 200rpx;
		color: #ffffff;
		font-weight: bold;
		padding-left: 30rpx;
		font-size: 28rpx !important;
		padding-bottom: 16rpx;
		border-top-right-radius: 200rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		border-top-left-radius: 200rpx;
		margin-top: 0rpx;
		border-bottom-right-radius: 200rpx;
		background-image: linear-gradient(to right, #fa2209, #ff6335);
		margin-bottom: 0rpx;
		padding-right: 30rpx;
	}
	.container329916 {
		background-color: #f5f5f5;
	}
	.container {
		padding-bottom: 100px;
	}
</style>
